package org.checkboo.hopefullyengine.text;

import org.checkboo.hopefullyengine.sceneelements.Color;
import org.checkboo.math.Vector2f;
import org.lwjgl.opengl.GL11;



public class Text {

	private String name;
	private String text;
	private Font font;
	private Color color;
	private Vector2f position;
	private Vector2f scale;
	
	public Text(String name, String text, Font font, Color color, Vector2f position, Vector2f scale){
		this.name = name;
		this.text = text;
		this.font = font;
		this.color = color;
		this.position = position;
		this.scale = scale;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getText() {
		return text;
	}

	public void setText(String text) {
		this.text = text;
	}
	
	public Font getFont() {
		return font;
	}

	public void setFont(Font font) {
		this.font = font;
	}

	public Color getColor() {
		return color;
	}

	public void setColor(Color color) {
		this.color = color;
	}

	public Vector2f getPosition() {
		return position;
	}

	public void setPosition(Vector2f position) {
		this.position = position;
	}

	public Vector2f getScale() {
		return scale;
	}

	public void setScale(Vector2f scale) {
		this.scale = scale;
	}

	public void render(){
        GL11.glBindTexture(GL11.GL_TEXTURE_2D, this.font.getFont().getTexturePointer());           // Select Our Font Texture
        GL11.glDisable(GL11.GL_DEPTH_TEST);                           // Disables Depth Testing	
        GL11.glDisable(GL11.GL_CULL_FACE);
        GL11.glDisable(GL11.GL_LIGHTING);
        GL11.glMatrixMode(GL11.GL_PROJECTION); 						// Select The Projection Matrix
        GL11.glPushMatrix();                                     // Store The Projection Matrix
        GL11.glLoadIdentity();                                   // Reset The Projection Matrix
        GL11.glOrtho(0, 1280, 0, 720, -1, 1);                          // Set Up An Ortho Screen
        GL11.glMatrixMode(GL11.GL_MODELVIEW);                         // Select The Modelview Matrix
        GL11.glPushMatrix();                                     // Store The Modelview Matrix
        GL11.glLoadIdentity();                                   // Reset The Modelview Matrix
        GL11.glTranslatef(this.position.getX(), this.position.getY(), 0);                                // Position The Text (0,0 - Bottom Left)
        GL11.glScalef(this.scale.getX(), this.scale.getY(), 1.0f);
        int baseOffset = this.font.getListBase() - 32;                // Choose The Font Set (0 or 1)
        for(int i=0;i<text.length();i++) {
        	GL11.glColor4f(this.color.getRed(), this.color.getGreen(), this.color.getBlue(), this.color.getAlpha());   
            GL11.glCallList(baseOffset + text.charAt(i));
            GL11.glTranslatef(1.0f, 0.0f, 0.0f);
        }
        GL11.glMatrixMode(GL11.GL_PROJECTION);                        // Select The Projection Matrix
        GL11.glPopMatrix();                                      // Restore The Old Projection Matrix
        GL11.glMatrixMode(GL11.GL_MODELVIEW);                         // Select The Modelview Matrix
        GL11.glPopMatrix();                                      // Restore The Old Projection Matrix
        GL11.glEnable(GL11.GL_DEPTH_TEST);    
        GL11.glEnable(GL11.GL_CULL_FACE);
        GL11.glEnable(GL11.GL_LIGHTING);// Enables Depth Testing
	}
}
